package com.guoyw.rabbitmq.rabbitmq.consumer.basics;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @Description: TODO
 * @Author: guoyw
 * @CreateDate: 2021/3/20 8:19 下午
 * @Version: 1.0
 */
@Configuration
public class RabbitmqConfig {

  public static final String EXCHANGE_NAME="basics-exchange";
  public static final String QUEUE_NAME = "rabbitmq-basics-queue";
  public static final String ROUTING_KEY = "rabbitmq.basics.#";

  @Bean("basicsExchange")
  public Exchange basicsExchange(){
    return ExchangeBuilder.topicExchange(EXCHANGE_NAME).build();
  }

  @Bean("basingQueue")
  public Queue basingQueue(){
    return QueueBuilder.durable(QUEUE_NAME).build();
  }

  @Bean
  public Binding bindingQueueExchange(@Qualifier("basingQueue") Queue queue,
                                      @Qualifier("basicsExchange") Exchange exchange){
    return BindingBuilder.bind(queue).to(exchange).with(ROUTING_KEY).noargs();
  }

}
